var React = require('react');


var Bheader = require('../widget/Bheader');
var ajax = require('../tools/ajax');

module.exports = React.createClass({
    getInitialState: function () {
        return {
            theme:"Default",
            flag:false,

        }
    },

    componentDidMount: function () {

    },
    change(){
        var nickname = this.refs.nickname.value;
        if(nickname){
            this.setState({flag:true});
        }else {
            this.setState({flag:false});
        }
    },
    nickname(){
        var p = this;
        var nickname = this.refs.nickname.value;
        var userId = localStorage.getItem("userId");
        ajax("POST","nickname",{userId:userId,nickname:nickname},function(dt){
            if(dt&&dt.success){
                location.href = "#userinfo";
            }
        })
    },
    render: function () {
        var p = this;

        return (
            <div className="main"  id="main">
                <Bheader theme={p.state.theme} headr="false" title="修改昵称" hact="#userinfo"></Bheader>
                <div className="container-t">
                    <hr className="orderHr"/>
                    <div className="nickname">
                        <input ref="nickname" onChange={p.change} type="text" placeholder="请填写昵称" onfocus="this.placeholder=''" onblur="this.placeholder='请填写昵称'" />
                        <div className={p.state.flag?"btn active":"btn"} onClick={p.nickname}>
                            保存
                        </div>
                    </div>
                </div>
            </div>
        )
    }
});
